﻿using AutoMapper;
using Modules;
using Modules.Attachment;
using Modules.Device;
using Modules.Manager;
using Modules.Project;
using Modules.System.Role;
using PmSoft;
using PmSoft.Entity;
using System.ComponentModel.DataAnnotations;
using static Modules.Project.ProjectConstants;

namespace ManagementApi.Models.Project
{
    public class ProjectUpdateApplyPageDto
    {
        public int Id { get; set; }

        /// <summary>
        /// 创建时间
        ///</summary>
        public DateTime CreateTime { get; set; } = DateTime.Now;

        /// <summary>
        /// 创建时间
        ///</summary>
        public string Creator { get; set; }

        /// <summary>
        /// 审核类型
        /// </summary>
        public 项目修改申请状态 AuditType { get; set; }

        /// <summary>
        /// 审核类型
        /// </summary>
        public string AuditTypeName { get; set; }

        /*额外字段*/

        /// <summary>
        /// 项目明朝
        /// </summary>
        public string projectName { get; set; }

        /// <summary>
        /// 项目编码
        /// </summary>
        public string projectNum { get; set; }
    }

    public static class ProjectUpdateApplyPageExceptions
    {
        /// <summary>
        /// </summary>
        /// <param name="projectUpdateApply"></param>
        /// <returns></returns>
        public static ProjectUpdateApplyPageDto AsPageDto(this ProjectUpdateApply projectUpdateApply)
        {
            ProjectUpdateApplyPageDto dto = new();
            var projectService = ServiceAccessor.GetService<ProjectService>();
            var project = projectService.GetProjectInfo(projectUpdateApply.ProjectId);
            dto.Creator = projectUpdateApply.Creator;
            dto.CreateTime = projectUpdateApply.CreateTime;
            dto.AuditType = projectUpdateApply.AuditType;
            dto.AuditTypeName = projectUpdateApply.AuditType.GetDescription();
            dto.Id = projectUpdateApply.Id;
            dto.projectName = project?.Name ?? string.Empty;
            dto.projectNum = project?.PrjNum ?? string.Empty;
            return dto;
        }
    }
}